<?php
/**
 * cms文章
 *
 *
 * * @网店运维 (c) 2015-2018 ShopWWI Inc. (http://www.shopwwi.com)
 * @license    http://www.shopwwi.c om
 * @link       交流群号：111731672
 * @since      网店运维提供技术支持 授权请购买shopnc授权
 */



defined('ByShopWWI') or exit('Access Invalid!');
class talk_showControl extends CMSHomeControl{

    public function __construct() {

        parent::__construct();
        Tpl::output('index_sign', 'talk_show');
    }

    public function indexOp() {

        $page_number = 100;
        $model_article = Model('cms_article');
        $para='talk_show';
        $class_id= $model_article->article_select($para);
        $condition['article_class_id']= $class_id;
        $article_list = $model_article->getList($condition, $page_number, 'article_sort asc, article_id desc');
        Tpl::output('show_page', $model_article->showpage(2));
        Tpl::output('article_li', $article_list);
        Tpl::showpage('talk_show');
    }



    /**
     * 文章列表
     */
    public function talk_detailOp() {
        $model_article = Model('cms_article');
        $talk_id= $this->article_id('talk_show');

        if(isset($_GET['article_id'])){
            $article_id = intval($_GET['article_id']);
            if(!in_array($article_id, $talk_id)) showMessage(Language::get('article_not_exist'),  CMS_SITE_TALK, '', 'error');

            if($article_id <= 0) {
                showMessage(Language::get('wrong_argument'),'','','error');
            }
        }else{
            $article_id= $talk_id[0];
        }


        //白银讲坛
        $talk_show_class_id=$model_article->article_select('talk_show');
        $article_detail = $model_article->getOne(array('article_id'=>$article_id));
        if(empty($article_detail)) {
            showMessage(Language::get('article_not_exist'), CMS_SITE_TALK, '', 'error');
        }


        //计数加1
        $model_article->modify(array('article_click'=>array('exp','article_click+1')),array('article_id'=>$article_id));

        //文章心情
        $article_attitude_list = array();
        $article_attitude_list[1] = Language::get('attitude1');
        $article_attitude_list[2] = Language::get('attitude2');
        $article_attitude_list[3] = Language::get('attitude3');
        $article_attitude_list[4] = Language::get('attitude4');
        $article_attitude_list[5] = Language::get('attitude5');
        $article_attitude_list[6] = Language::get('attitude6');
        Tpl::output('article_attitude_list', $article_attitude_list);

        $condition=array();
        $condition['article_class_id'] = array('in',"$talk_show_class_id");
        $ar_id_next= $model_article->articel_list($article_id, 'next',$condition);
        $ar_id_pre= $model_article->articel_list($article_id, 'pre',$condition);
        $bar_list=$model_article->bar_article(10,$condition);
        Tpl::output('id_next', $ar_id_next);
        Tpl::output('id_pre', $ar_id_pre);
        Tpl::output('bar_list', $bar_list);

        //分享
        $this->get_share_app_list();

        Tpl::output('article_detail', $article_detail);
        Tpl::output('detail_object_id', $article_id);

        //seo
        Tpl::output('seo_title', $article_detail['article_title']);

        Tpl::showpage('talk_detail');
    }

    private function article_id($para){
        $model_article = Model('cms_article');
        $condition_array= array();
        $article_id= array();
        $class_id=$model_article->article_select($para);
        $condition_array['article_class_id']= $class_id;
        $para_id= $model_article->getList($condition_array, $page=null, $order='', $field='article_id', $limit='');
        foreach ($para_id as $value){
            array_push($article_id, $value['article_id']);
        }
        return $article_id;
    }



    /**
     * 文章列表
     */
    public function article_searchOp() {
        $condition = array();
        $condition['article_title'] = array("like",'%'.trim($_GET['keyword']).'%');
        $condition['article_state'] = self::ARTICLE_STATE_PUBLISHED;
        $model_article = Model('cms_article');
        $article_list = $model_article->getList($condition, 20, 'article_sort asc, article_id desc');
        Tpl::output('show_page', $model_article->showpage(2));
        Tpl::output('total_num', $model_article->gettotalnum());
        Tpl::output('article_list', $article_list);
        $this->get_article_sidebar();

        Tpl::showpage('search_article');
    }





}
